use crate::middleware::jwt::AuthBody;
use crate::dto::sys_user::UserLoginReq;
use crate::util::rand_utils::encrypt_password;
use crate::util::web_utils::get_client_info;
use hypers::prelude::{Result,Error};
use hypers::prelude::Request;


/// 用户登录
pub async fn login(login_req: UserLoginReq, req: &Request) -> Result<AuthBody> {
    let mut msg = "登录成功".to_string();
    let mut status = "1".to_string();
    // 验证验证码
    if encrypt_password(&login_req.code, "") != login_req.uuid {
        msg = "验证码错误".to_string();
        status = "0".to_string();
        return Err(Error::Other("验证码错误".to_owned()));
    }
    todo!()
}

pub async fn set_login_info(req: &Request, u_id: String, user: String, msg: String, status: String, token_id: Option<String>, token: Option<AuthBody>) {
    let header = req.headers().to_owned();
    let remote_addr = req.remote_addr().to_owned();
    let u = get_client_info(header, remote_addr).await;

    // 写入登录日志
    // 如果成功，写入在线日志
    if status == "1" {
        if let (Some(token_id), Some(token)) = (token_id, token) {
            
        }
    }

}